﻿using System.Web.Mvc;
using Api.BLL;
using Api.Model;
using System.Collections.Generic;
using Api.Web.filter;
using System.Linq;

namespace Api.Web.Controllers
{
    public class HomeController : BaseController
    {
        public ActionResult ProjectList()
        {
            var list = ProjectBLL.Current.GetListNoTrack(s => s.UserId == userId);
            if (list == null)
            {
                return View("_500");
            }
            return View(list);
        }
        public ActionResult Index(int? categoryId)
        {
            ViewBag.Categories = new List<Category>();
            ViewBag.Methods = new List<Method>();

            var list = CategoryBLL.Current.GetListNoTrack(s => s.ParentId == 0 && projectId == s.ProjectId && s.UserId == userId);
            if (list == null) return View("_500");
            ViewBag.Categories = list;
            if (categoryId == null && list.Count > 0)
            {
                categoryId = list[0].Id;
            }
            if (categoryId != null)
            {
                var methods = MethodBLL.Current.GetList(s => s.CategoryId == categoryId && s.UserId == userId);
                if (methods == null) return View("_500");
                ViewBag.Methods = methods;
            }
            ViewBag.CateogryId = categoryId;
            return View();
        }

        public ActionResult Problem()
        {
            var problem = ProblemBLL.Current.GetModel(s => s.ProjectId == projectId && s.Type == "Problem");
            return View(problem);
        }

        public ActionResult Demand()
        {
            var problem = ProblemBLL.Current.GetModel(s => s.ProjectId == projectId && s.Type == "Demand");
            return View(problem);
        }
    }
}